(function() {
  var $, Task, TasksController, TomatoBreak, refreshListView;
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
    for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
    function ctor() { this.constructor = child; }
    ctor.prototype = parent.prototype;
    child.prototype = new ctor;
    child.__super__ = parent.prototype;
    return child;
  };
  TomatoBreak = this.TomatoBreak;
  $ = jQuery;
  Task = TomatoBreak.Task;
  refreshListView = function(list) {
    if (list.jqmData('listview')) {
      list.listview('destroy');
    }
    return list.listview({
      inset: true
    });
  };
  TasksController = (function() {
    __extends(TasksController, Spine.Controller);
    TasksController.elements = {
      '.list': 'list',
      '.template': 'template'
    };
    function TasksController() {
      this.render = __bind(this.render, this);
      this.removed = __bind(this.removed, this);
      this.updated = __bind(this.updated, this);
      this.created = __bind(this.created, this);      TasksController.__super__.constructor.apply(this, arguments);
      Task.bind('create', this.created);
      Task.bind('update', this.updated);
      Task.bind('destroy', this.removed);
      Task.bind('refresh', this.render);
    }
    TasksController.prototype.activate = function() {
      return Task.fetch();
    };
    TasksController.prototype.reset = function() {};
    TasksController.prototype.created = function(task) {
      this.list.append(this.template.tmpl(task));
      return refreshListView(this.list);
    };
    TasksController.prototype.updated = function(task) {
      ($("li[data-taskId=" + task.id + "]", this.list)).replaceWith(this.template.tmpl(task));
      return refreshListView(this.list);
    };
    TasksController.prototype.removed = function(task) {
      ($("li[data-taskId=" + task.id + "]", this.list)).remove();
      return refreshListView(this.list);
    };
    TasksController.prototype.render = function() {
      var task, _i, _len, _ref;
      this.list.empty();
      _ref = Task.all();
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        task = _ref[_i];
        this.list.append(this.template.tmpl(task));
      }
      return refreshListView(this.list);
    };
    return TasksController;
  })();
  TomatoBreak.TasksController = TasksController;
}).call(this);
